execute_process(
	COMMAND git describe --long --tags --dirty --always
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
	OUTPUT_VARIABLE VERSION
	OUTPUT_STRIP_TRAILING_WHITESPACE
)

string(REPLACE "-" ";" VERSION_STR ${VERSION})
list(GET VERSION_STR 0 VERSION_NUMBER)
string(REPLACE "v" "" VERSION_NUMBER_LIST ${VERSION_NUMBER})
string(REPLACE "." ";" VERSION_NUMBER_LIST ${VERSION_NUMBER_LIST})
list(GET VERSION_NUMBER_LIST 0 VERSION_MAJOR)

list(LENGTH VERSION_NUMBER_LIST VERSION_NUMBER_LIST_COUNT)

if (${VERSION_NUMBER_LIST_COUNT} GREATER_EQUAL 2)
list(GET VERSION_NUMBER_LIST 1 VERSION_MINOR)
list(GET VERSION_STR 1 VERSION_PATCH)
endif()

if (${VERSION_NUMBER_LIST_COUNT} GREATER_EQUAL 3)
	list(GET VERSION_NUMBER_LIST 2 BUILD_NUMBER_ORG)
	MATH(EXPR VERSION_PATCH "${BUILD_NUMBER_ORG} + ${VERSION_PATCH}")
endif()

set(VERSION_TAG "v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

string(TIMESTAMP BUILD_DATE "\"%Y-%m-%dT%H:%M:%SZ\"" UTC)
